﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using CinemaDbLib;
using ModelLayer;

// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "UserCtrl" in code, svc and config file together.
public class UserCtrl : IUserCtrl
{
	private UserDB userDB;

	public UserCtrl()
	{
		userDB = new UserDB();
	}

	public int addUser(string name, string email, string password)
	{
		User user = new User(-1, email, password, name);

		return userDB.insertUser(user);
	}

	public bool removeUser(int id)
	{
		return userDB.removeUser(id);
	}

	public bool updateUser(int id, string name, string email, string password)
	{
		User user = new User(id, email, password, name);

		return userDB.updateUser(user);
	}

	public User getUser(int id)
	{
		return userDB.getUserById(id);
	}

	public User[] getUsers()
	{
		return userDB.getUsers().ToArray();
	}

    public User getUser(string username)
    {
        return userDB.getUserByUsername(username);
    }
}
